package com.diandi.signature.service.impl.signatureca;

import com.diandi.signature.bean.cainfo.SignatureCAInfo;
import com.diandi.signature.manager.CAInfo.CADataManager;
import com.diandi.signature.signatureca.CADataService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by mxp on 2017/12/15.
 */
@Service
public class CADataServiceImpl implements CADataService {
    private Logger logger = LoggerFactory.getLogger(CADataServiceImpl.class);

    @Autowired
    private CADataManager caDataManager;

    @Override
    public Map<String, Object> queryList(String userId, Integer page, Integer rows) {
        Map<String, Object> returnMap = new HashMap<String, Object>();
        Map<String, Object> paramMap = new HashMap<String, Object>();

        int from = (page - 1) * rows;
        paramMap.put("from", from);
        paramMap.put("rows", rows);

        if (StringUtils.isNotBlank(userId)){
            paramMap.put("userId", userId);
        }

        List<SignatureCAInfo> caList = caDataManager.queryList(paramMap);
        Integer count = caDataManager.queryCount(paramMap);

        returnMap.put("total", count);
        returnMap.put("rows", caList);

        return returnMap;
    }
}